package com.rao.mongodb.explorer.common.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * 容器初始化存储路径
 *
 * @author raos
 * @emil 991207823@qq.com
 * @date 2021/8/31 22:21
 */
@Slf4j
@Component
public class InitExplorerApplicationRunner implements ApplicationRunner {

    @Autowired
    private ExplorerConfig explorerConfig;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("文件存储路径初始化开始...");
        File file = new File(explorerConfig.getRootDir());
        if (!file.exists()) {
            file.mkdirs();
            log.info("初始化文件存储根目录...");
        }
        file = new File(explorerConfig.getFilesDepotDir());
        if (!file.exists()) {
            file.mkdirs();
            log.info("初始化文件存储仓库目录...");
        }
        file = new File(explorerConfig.getTempRootDir());
        if (!file.exists()) {
            file.mkdirs();
            log.info("初始化临时文件根目录...");
        }
        file = new File(explorerConfig.getUsersRootDir());
        if (!file.exists()) {
            file.mkdirs();
            log.info("初始化文件存储用户根目录...");
        }
        file = new File(explorerConfig.getPublicRootDir());
        if (!file.exists()) {
            file.mkdirs();
            log.info("初始化文件公共资源根目录...");
        }
        log.info("文件存储路径初始化结束...");
    }

}
